package function

import (
	"context"
	"wh-1-backend/internal/dao"
	"wh-1-backend/internal/model/entity"
	"wh-1-backend/internal/service"
)

type sFunction struct {
}

func New() *sFunction {
	return &sFunction{}
}

func init() {
	service.RegisterFunction(New())
}

func (f *sFunction) ListByPid(ctx context.Context, pid uint) (res []*entity.Function, err error) {
	err = dao.Function.Ctx(ctx).Where(dao.Function.Columns().Pid, pid).Scan(&res)
	return
}

func (f *sFunction) List(ctx context.Context) (res []*entity.Function, err error) {
	err = dao.Function.Ctx(ctx).Scan(&res)
	return
}

func (f *sFunction) ListByIds(ctx context.Context, ids []uint) (res []*entity.Function, err error) {
	err = dao.Function.Ctx(ctx).WhereIn(dao.Function.Columns().Id, ids).Scan(&res)
	return
}
